package reflect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @description:动态代理类
 * @author: guole
 * @date: 2020/3/28
 */
public class MyInvocationHandler  implements InvocationHandler {
    private Object object;
    private LogClass logClass;
    public MyInvocationHandler(Object object,LogClass logClass){
        this.object=object;
        this.logClass=logClass;
    }
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        Object invoke= null;
        try {
            logClass.befor();
            invoke = method.invoke(object,args);
            logClass.after();
         } catch (Exception e) {
             return  e.getCause().getMessage();

        }
         return invoke;
    }
}
